package com.huffman.smart_picture.utils;

import java.util.Arrays;
import java.util.List;

/**
 * @author DengLin
 * @title 字符串工具
 * @date 2024/07/03
 */
public class StringUtil {
    private StringUtil() {

    }

    /**
     * 将List转为字符串
     *
     * @param list
     * @param split
     * @param <T>
     * @return
     */
    public static <T> String join(List<T> list, String split) {
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i).toString());
            if (i != list.size() - 1) {
                sb.append(split);
            }
        }
        sb.append(']');
        return sb.toString();
    }

    /**
     * 将数组转为字符串
     *
     * @param args
     * @param split
     * @return
     */
    public static String join(Object[] args, String split) {
        return join(Arrays.asList(args), split);
    }
}
